﻿#ifndef LICENSECODEMANAGEMENT_H
#define LICENSECODEMANAGEMENT_H

#include <QCryptographicHash>
#include <QDebug>
#include <QTextStream>
#include <QFile>
#include <QProcess>
#include <QtNetwork/QNetworkInterface>
#include <QtNetwork/QHostAddress>
#include <QDateTime>
#include "LicenseCodeManagement_global.h"
#include "aesni/qaesencryption.h"
#define AES_KEY "CJJM2501"

enum ResultCode
{
    SUCCESS=0,  //授权成功
    FILE_NOT_EXIST, //文件不存在
    FILE_READ_FAILED, //文件读取失败
    NO_LICENSE, //该设备未被授权
    LICENSE_DATE_ERROR //授权日期错误
};

class LICENSECODEMANAGEMENT_EXPORT LicenseCodeManagement
{
public:
    LicenseCodeManagement();
    void licenseValidate(QString licenseStr, bool creatFileFlag); //授权验证
    QString getMachineCode(); //获取机器码
    ResultCode getResultCode(); //获取授权结果码
    QString getPlaneTypeID(); //获取机型id
    //    void licenseVerificationModule(); //TODO打开授权验证模块

private:
    QString getHardwareSerialNumber(const QString &cmd); //获取硬件序列号：CPU和硬盘
    QString getMacAddress(); //获取MAC地址
    QString encryptionMD5(const QString &data); //MD5加密
    QString decryptionAES(QString data , QString key); //AES解密
    QString m_DecryptionContextStr; //解密后的内容
    QString m_MachineCode; //机器码
    QDate m_StartDate; //起始日期
    QDate m_EndDate; //结束日期
    QDate m_CurrentDate; //当前系统日期
    QStringList m_PlaneTypeIDList; //机型id
    QString m_FilePath; //授权码文件路径
    ResultCode m_ResultCode; //授权结果码
    QString m_PlaneTypeIDStr; //机型id
};

#endif // LICENSECODEMANAGEMENT_H
